package com.gla.service;

import com.gla.dao.EvaluationMapper;
import com.gla.dao.OrderMapper;
import com.gla.domain.Evaluation;
import com.gla.domain.Order;
import com.gla.domain.OrderDetailResponse;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EvaluationService {

    @Resource
    EvaluationMapper evaluationMapper;
    @Resource
    OrderMapper orderMapper;

    public void add(Integer order_id, Integer ratting, String evaluation) {
        Map<String, Object> map = new HashMap();
        map.put("order_id",order_id);
        Order order = orderMapper.select(map).get(0);
        List<OrderDetailResponse> list = orderMapper.selectOrderDetailByOrderId(order_id);
        //创建评价对象
        Evaluation evaluationObj = new Evaluation();
        evaluationObj.setPoint(ratting);
        evaluationObj.setCommodity(list.get(0).getCommodity().getId());
        evaluationObj.setShop_id(list.get(0).getCommodity().getShop().getId());
        evaluationObj.setUser_id(order.getUser_id());
        evaluationObj.setEvaluation(evaluation);
        evaluationMapper.add(evaluationObj);
    }
}
